package pe.edu.sistemas.postgrado.samupg.repository.dao.implHib;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;
import pe.edu.sistemas.postgrado.samupg.repository.dao.ExamenDAO;
import pe.edu.sistemas.postgrado.samupg.domain.model.Examen;
import pe.edu.sistemas.postgrado.samupg.domain.model.Pregunta;

@Repository
public class ExamenDAOImpl implements ExamenDAO {

    @Autowired
    private SessionFactory sessionFactory;

    @Override
    public Examen findxId(Integer idExamen) throws DataAccessException {
        Examen examen;
        examen = (Examen) sessionFactory.getCurrentSession().get(Examen.class, idExamen);
        return examen;
    }

    @Override
    public List<Pregunta> getPreguntasxId(Integer idExamen) throws DataAccessException {
        Examen examen = findxId(idExamen);
        if (examen == null) {
            return null;
        }
        
        return examen.getPreguntas();
    }
}
